//
//  HomeViewController.m
//  Koizora
//
//  Created by dlios on 15-6-8.
//  Copyright (c) 2015年 CupCat. All rights reserved.
//

#import "HomeViewController.h"
#import "HomeView.h"
#import "ExchangeStarView.h"
#import "LuckyMonthModel.h"
#import "NetworkHandle.h"
#import "LuckyMonthView.h"
#import "LuckyTomorrowModel.h"
#import "CatSuperView.h"
#import "HomeTestViewController.h"
#import "ChooseView.h"
#import "HomeUserViewController.h"
#import "HomeArticleViewController.h"


@interface HomeViewController ()<TouchStatusDelegate,JumpTo>

@property (nonatomic, strong) HomeView *luckView;
@property (nonatomic, strong) ExchangeStarView *exchangeView;
@property (nonatomic, assign) BOOL bol;
@property (nonatomic, strong) LuckyMonthModel *lmm;
@property (nonatomic, strong) LuckyTomorrowModel *today;
@property (nonatomic, strong) LuckyTomorrowModel *tomorrow;
@property (nonatomic, strong) LuckyMonthView *luckyMonth;
@property (nonatomic, retain) NSMutableArray *detailArr;
@property (nonatomic, retain) CatSuperView *detaliNavigation;
@property (nonatomic, retain) CatSuperModel *lhdm;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.bol = NO;
    self.view.backgroundColor = [UIColor whiteColor];
//    self.navigationController.navigationBarHidden = YES;
//    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"白羊座"]];
    [self Navigation];
    [self getData];
    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
}

// 创建运势页面
- (void)createLuckyView
{
    self.luckView = [[HomeView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64)];
    _luckView.luckyMonth.lianqing.text = _lmm.lianqing;
    _luckView.luckyMonth.gongzuo.text = _lmm.gongzuo;
    _luckView.luckyMonth.qiuzhi.text = _lmm.qiuzhi;
    _luckView.luckyMonth.caiyun.text = _lmm.caiyun;
    _luckView.luckyMonth.jiankang.text = _lmm.jiankang;
    
    _luckView.luckyToday.xingyunse.text = _today.xingyunse;
    _luckView.luckyToday.xingyunshu.text = _today.xingyunshu;
    _luckView.luckyToday.supei.text = _today.supei;
    _luckView.luckyToday.content.text = _today.content;
    
    _luckView.luckyTomorrow.xingyunse.text = _tomorrow.xingyunse;
    _luckView.luckyTomorrow.xingyunshu.text = _tomorrow.xingyunshu;
    _luckView.luckyTomorrow.content.text = _tomorrow.content;
    _luckView.luckyTomorrow.supei.text = _tomorrow.supei;

    self.luckView.delegate = self;
    _luckView.userInteractionEnabled = YES;
    [self.view addSubview:_luckView];

}

- (void)Navigation
{
    self.detaliNavigation = [[CatSuperView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    _detaliNavigation.rightTarget = self;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]init];
    _detaliNavigation.rightAction = @selector(press:);
    [_detaliNavigation creatRightButtonToShareOrCollect:@"53c7085374637" gestrue:tap];
    [self.view addSubview:_detaliNavigation];
    
    
}
- (void)createExchangeView
{
    self.exchangeView = [[ExchangeStarView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 6, self.view.frame.size.height / 7 + 60 + 20, 250, 250)];
    [self.view addSubview:_exchangeView];
}

- (void)TouchStatus
{
    if (_bol == NO) {

        [self createExchangeView];

        _bol = YES;
        
    } else {
        
        [self.exchangeView removeFromSuperview];
        
        _bol = NO;
        
    }
}
- (void)getData
{
    [NetworkHandle getDataWithURL:@"http://star.zhuoyouapp.com/v1/forecastServer/getLuckWeek?xz=%E5%A4%84%E5%A5%B3%E5%BA%A7" completion:^(id result) {
        
        self.lmm = [[LuckyMonthModel alloc] initWithDic:[result objectForKey:@"entity"]];
        NSLog(@"%@",_lmm);
        [NetworkHandle getDataWithURL:@"http://star.zhuoyouapp.com/v1/forecastServer/getLuckDay?xz=%E5%A4%84%E5%A5%B3%E5%BA%A7&type=today" completion:^(id result) {
            self.today = [[LuckyTomorrowModel alloc] initWithDic:[result objectForKey:@"entity"]];
            NSLog(@"%@",_today);
            [NetworkHandle getDataWithURL:@"http://star.zhuoyouapp.com/v1/forecastServer/getLuckDay?xz=%E5%A4%84%E5%A5%B3%E5%BA%A7&type=tomorrow" completion:^(id result) {
                self.tomorrow = [[LuckyTomorrowModel alloc] initWithDic:[result objectForKey:@"entity"]];
                NSLog(@"%@",_tomorrow);
                [self createLuckyView];
            }];
        }];
    }];
}

- (void) press: (UIGestureRecognizer *) gestureRecognizer
{
    ChooseView *chooseView = [[ChooseView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width  - 50, 64, 40, 140)];
    chooseView.backgroundColor = [UIColor redColor];
    [self.view addSubview:chooseView];
    chooseView.delegate = self;
}
- (void)pushButton1
{
    HomeTestViewController *homeTest = [[HomeTestViewController alloc] init];
    [self.navigationController pushViewController:homeTest animated:YES];
}
- (void)pushButton2
{
    HomeArticleViewController *homeTest = [[HomeArticleViewController alloc] init];
    [self.navigationController pushViewController:homeTest animated:YES];
}

- (void)pushButton3
{
    HomeUserViewController *homeUser = [[HomeUserViewController alloc] init];
    [self.navigationController pushViewController:homeUser animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
